CREATE TABLE [dbo].[RuleMain]
(
[RuleKey] [uniqueidentifier] NOT NULL,
[Name] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[Description] [nvarchar] (200) COLLATE SQL_Latin1_General_CP1_CI_AS NULL CONSTRAINT [DF_RuleMain_Description] DEFAULT (''),
[IsActive] [bit] NOT NULL,
[Priority] [int] NOT NULL CONSTRAINT [DF_RuleMain_Priority] DEFAULT ((999999)),
[BeginDate] [datetime] NULL,
[EndDate] [datetime] NULL,
[RuleEvaluatorComponentKey] [uniqueidentifier] NULL,
[ObjectMapperComponentKey] [uniqueidentifier] NULL,
[UpdatedOn] [datetime] NOT NULL CONSTRAINT [DF_RuleMain_UpdatedOn] DEFAULT (getdate()),
[UpdatedByUserKey] [uniqueidentifier] NOT NULL,
[CreatedByUserKey] [uniqueidentifier] NOT NULL,
[CreatedOn] [datetime] NOT NULL,
[SystemEntityKey] [uniqueidentifier] NOT NULL,
[MarkedForDeleteOn] [datetime] NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[RuleMain] ADD CONSTRAINT [PK_RuleMain] PRIMARY KEY CLUSTERED ([RuleKey]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_RuleMain_BeginDate_EndDate] ON [dbo].[RuleMain] ([BeginDate], [EndDate]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_RuleMain_CreatedByUserKey] ON [dbo].[RuleMain] ([CreatedByUserKey]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_RuleMain_ObjectMapperComponentKey] ON [dbo].[RuleMain] ([ObjectMapperComponentKey]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_RuleMain_RuleEvaluatorComponentKey] ON [dbo].[RuleMain] ([RuleEvaluatorComponentKey]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_RuleMain_SystemEntityKey] ON [dbo].[RuleMain] ([SystemEntityKey]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_RuleMain_UpdatedByUserKey] ON [dbo].[RuleMain] ([UpdatedByUserKey]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[RuleMain] ADD CONSTRAINT [FK_RuleMain_ComponentRegistry_ObjectMapper] FOREIGN KEY ([ObjectMapperComponentKey]) REFERENCES [dbo].[ComponentRegistry] ([ComponentKey])
GO
ALTER TABLE [dbo].[RuleMain] ADD CONSTRAINT [FK_RuleMain_ComponentRegistry_RuleEvaluator] FOREIGN KEY ([RuleEvaluatorComponentKey]) REFERENCES [dbo].[ComponentRegistry] ([ComponentKey])
GO
ALTER TABLE [dbo].[RuleMain] ADD CONSTRAINT [FK_RuleMain_SystemEntity] FOREIGN KEY ([SystemEntityKey]) REFERENCES [dbo].[SystemEntity] ([SystemEntityKey])
GO
ALTER TABLE [dbo].[RuleMain] ADD CONSTRAINT [FK_RuleMain_UserMain_CreatedBy] FOREIGN KEY ([CreatedByUserKey]) REFERENCES [dbo].[UserMain] ([UserKey])
GO
ALTER TABLE [dbo].[RuleMain] ADD CONSTRAINT [FK_RuleMain_UserMain_UpdatedBy] FOREIGN KEY ([UpdatedByUserKey]) REFERENCES [dbo].[UserMain] ([UserKey])
GO